package com.spring.boot.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spring.boot.entity.Ranking;
import com.spring.boot.mapper.RankingMapper;
import com.spring.boot.service.RankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RankingServiceImpl extends ServiceImpl<RankingMapper,Ranking> implements RankingService {
    @Autowired
    private RankingMapper rankingMapper;
    @Override
    public List<Ranking> getRankingInfo(String date) {
        QueryWrapper<Ranking> queryWrapper = new QueryWrapper<>();
        if (StrUtil.hasEmpty(date)){
            queryWrapper.orderByDesc("id").last("limit 10");
            List<Ranking> list = rankingMapper.selectList(queryWrapper);
            return list;
        }
        else {
            queryWrapper.eq("create_time",date).orderByDesc("create_time").last("limit 10");
            List<Ranking> list = rankingMapper.selectList(queryWrapper);
            return list;
        }

    }
}
